<?php
/*
 * Created on Feb 19, 2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 class place_Model_District extends Clu_Db_Table_Abstract
{
    //only specify the table name, everything else inherits
	protected $_name = "districts";
	protected $_primary = "district_id";
	
	public function findByPrimary($id)
	{
		if (!$id)
            return null;
        else
		    return $this->fetchRow('district_id = ' . $this->getAdapter()->quote($id, 'INTEGER'));
	}
	public function getDistrictName($district_id)
	{
		$db = $this->getAdapter();
    	$sql = "SELECT * FROM districts d WHERE district_id =" .$db->quote($district_id,'INTEGER');
	    return $db->fetchRow($sql);
	}
	
	public function getDistricts($city_id)
    {
	    $db = $this->getAdapter();
	    $select = $this->getAdapter()->select()
    								 ->from(array('d' => 'districts'))
    								 ->where('d.city_id = ?', $db->quote($city_id,'INTEGER'));
    	$select->order(array('status', 'weight'));
    	$ret = $this->getAdapter()->fetchAll($select);
//	    $sql = "SELECT * FROM districts d WHERE city_id =" .$db->quote($city_id,'INTEGER');
	    //$select = $db->query($sql);
	    //return $select->fetchAll();
	    return $ret;
	}
}
?>
